/*
 * QryOpti.cpp
 *
 *  Created on: 09-Jan-2010
 *      Author: pankaj
 */

#include "QryOpti.h"

void QryOpti::quicksort(int a, int b,vector<unsigned char*> &A) {
	int maxsize = A.size();
	int rtidx = 0, ltidx = 0, k = a, l = 0;
	unsigned char* pivot;
	unsigned char* leftarr[maxsize], *rtarr[maxsize];
	copy(A[a],pivot);
	pivot = A[a];
	if (a == b)
		return;
	while (k < b) {
		++k;
		if (compare(A[k], A[a])) {
			copy(A[k],leftarr[ltidx]);
			ltidx++;
		} else {
			copy(A[k],rtarr[rtidx]);
			rtidx++;
		}
	}

	k = a;
	for (l = 0; l < ltidx; ++l)
		copy(leftarr[l],A[k++]);
	copy(pivot,A[k++]);
	for (l = 0; l < rtidx; ++l)
		copy(rtarr[l],A[k++]);
	if (ltidx > 0)
		quicksort(a, a + ltidx - 1,A);
	if (rtidx > 0)
		quicksort(b - rtidx + 1, b,A);
}

int QryOpti::compare(unsigned char* rec1, unsigned char* rec2){
	return 0;
}

void QryOpti::copy(unsigned char* srec, unsigned char* drec){

}

int QryOpti::internalSort(Page pag) {
	return 0;
}

int QryOpti::sort(vector<int> inpagno, vector<unsigned char*> keyformat,
			int noskeyarg, vector<int> sortorder, int order, int reclen,
			vector<int> &outpagno){
	_keyformat = keyformat;
	_noskeyarg = noskeyarg;
	_sortorder = sortorder;
	_order = order;
	_reclen = reclen;
	_nosrec = PAGE_SIZE / reclen;

	return 1;
}

QryOpti::QryOpti() {
	// TODO Auto-generated constructor stub

}

QryOpti::~QryOpti() {
	// TODO Auto-generated destructor stub
}
